home *** CD-ROM | disk | FTP | other *** search
- /* ///////////////////////////////////////////////////////////////////
- // $Id: arcmkdrawf.c,v 1.0 1995/08/29 06:03:13 Exp $
- * Revision 1.0 1.0 1995/08/29 06:03:13
- * Acorn RISC OS draw writer, contributed by Maurizio Ferrari
- * (ferrari@bologna.marelli.it).
- *
- //
- // File: arcmkdrawf.c
- //
- // Descript: RISC OS draw drivers
- //
- // Library: ---
- //
- // Requires: ---
- //
- // Public: plD_init_arcmkdrawf()
- // plD_line_arcmkdrawf()
- // plD_polyline_arcmkdrawf()
- // plD_eop_arcmkdrawf()
- // plD_bop_arcmkdrawf()
- // plD_tidy_arcmkdrawf()
- // plD_state_arcmkdrawf()
- // plD_esc_arcmkdrawf()
- //
- // pldummy_arcmkdrawf()
- //
- // Private: arcmkdrawf_initialize_pls()
- //
- // Notes: ---
- //
- // Revisions:
- /////////////////////////////////////////////////////////////////// */
-
- #include "plDevs.h"
-
- #if defined(PLD_arcmkdrawf)
-
- #include "plplotP.h"
- #include <stdio.h>
- #include <string.h>
- #include "drivers.h"
-
-
- /* top level declarations */
-
- /* Page sizes */
-
- #define ARCDRAW_XMIN 25
- #define ARCDRAW_XMAX 800
- #define ARCDRAW_YMIN 30
- #define ARCDRAW_YMAX 580
- #define ARCDRAW_XRATIO 4.
- #define ARCDRAW_YRATIO 4.
-
-
- static struct lvs {
- int path_is_open;
- int width_has_changed;
- int color_0_has_changed;
- int color_1_has_changed;
- int x1st;
- int y1st;
- int xlast;
- int ylast;
- int fill_req;
- int must_close;
- int path_is_valid;
- PLColor fill_color;
- } local_v;
-
- /*local prototypes */
- static void arcmkdrawf_end_path(PLStream *, struct lvs *);
- static void arcmkdrawf_start_path(PLStream *, struct lvs *);
- static void arcmkdrawf_initialize_pls(PLStream *, struct lvs *);
- static void arcmkdrawf_change_colour0(PLStream *, struct lvs *);
- static void arcmkdrawf_change_colour1(PLStream *, struct lvs *);
- static void arcmkdrawf_change_width(PLStream *, struct lvs *);
-
- /*----------------------------------------------------------------------*\
- * arcmkdrawf_initialize_pls()
- *
- * Initialize plot stream
- \*----------------------------------------------------------------------*/
-
- static void
- arcmkdrawf_initialize_pls(PLStream *pls, struct lvs *l_v)
- {
-
- PLDev *dev = (PLDev *) pls->dev;
-
- /*clear local work variables*/
- l_v->path_is_open = FALSE;
- l_v->width_has_changed = FALSE;
- l_v->color_0_has_changed = FALSE;
- l_v->color_1_has_changed = FALSE;
- l_v->x1st = 0;
- l_v->y1st = 0;
- l_v->xlast = 0;
- l_v->ylast = 0;
- l_v->fill_req = FALSE;
- l_v->must_close = FALSE;
- l_v->path_is_valid = FALSE;
-
- pls->termin = 0; /* not an interactive terminal */
- pls->icol1 = 1;
- pls->bytecnt = 0;
- pls->page = 0;
- pls->family = 1; /* file has family */
- pls->dev_fill0 = 1; /* Can do solid fills */
-
- plFamInit(pls); /* Initialize family file info */
- plOpenFile(pls); /* get file name if not already set */
-
- dev->xold = UNDEFINED;
- dev->yold = UNDEFINED;
- dev->xlen = dev->xmax - dev->xmin;
- dev->ylen = dev->ymax - dev->ymin;
-
- plP_setpxl((PLFLT) ARCDRAW_XRATIO, (PLFLT) ARCDRAW_YRATIO);
- plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax);
-
- }
-
- /*----------------------------------------------------------------------*\
- * plD_init_arcmkdrawf()
- *
- * Initialize device.
- \*----------------------------------------------------------------------*/
-
- void
- plD_init_arcmkdrawf(PLStream *pls)
- {
- PLDev *dev;
-
- pls->color = 1;
- dev = plAllocDev(pls); /* Allocate device-specific data */
- dev->xmin = ARCDRAW_XMIN;
- dev->xmax = ARCDRAW_XMAX;
- dev->ymin = ARCDRAW_YMIN;
- dev->ymax = ARCDRAW_YMAX;
-
- arcmkdrawf_initialize_pls(pls, &local_v); /* initialize plot stream */
- }
-
- /*----------------------------------------------------------------------*\
- * plD_line_arcmkdrawf()
- *
- * Draw a line in the current color from (x1,y1) to (x2,y2).
- \*----------------------------------------------------------------------*/
-
- void
- plD_line_arcmkdrawf(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
- {
- PLDev *dev = (PLDev *) pls->dev;
- int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
-
- /* Write out old path */
- if (x1 != dev->xold || y1 != dev->yold) { /* Write out old path */
- if (local_v.path_is_open != FALSE) {
- arcmkdrawf_end_path(pls, &local_v);
- }
- local_v.path_is_open = TRUE;
- fputs( "#Line\n", pls->OutFile );
- arcmkdrawf_start_path(pls, &local_v);
- pls->bytecnt += fprintf( pls->OutFile, "Move %d %d\n", x1, y1 );
- local_v.x1st = x1; local_v.y1st = y1;
- local_v.color_0_has_changed = FALSE;
- local_v.color_1_has_changed = FALSE;
- }
- /* Add new point to path */
- if (local_v.width_has_changed == TRUE){
- arcmkdrawf_change_width(pls, &local_v);
- }
- if (local_v.color_0_has_changed == TRUE) {
- arcmkdrawf_change_colour0(pls, &local_v);
- }
- if (local_v.color_1_has_changed == TRUE) {
- arcmkdrawf_change_colour1(pls, &local_v);
- }
- pls->bytecnt += fprintf( pls->OutFile, "Line %d %d\n", x2, y2);
- local_v.xlast = x2; local_v.ylast = y2;
- if ((local_v.x1st != local_v.xlast) || (local_v.y1st != local_v.ylast)) {
- local_v.path_is_valid = TRUE;
- }
-
- dev->xold = x2;
- dev->yold = y2;
- }
-
- /*----------------------------------------------------------------------*\
- * plD_polyline_arcmkdrawf()
- *
- * Draw a polyline in the current color.
- \*----------------------------------------------------------------------*/
-
- void
- plD_polyline_arcmkdrawf(PLStream *pls, short *xa, short *ya, PLINT npts)
- {
- register PLINT i;
- PLDev *dev = (PLDev *) pls->dev;
-
-
- /* Write out old path */
- /* if (xa[0] != dev->xold || ya[0] != dev->yold) {*/
- if (local_v.path_is_open != FALSE) {
- arcmkdrawf_end_path(pls, &local_v);
- }
- fputs( "#Polyline\n", pls->OutFile );
- arcmkdrawf_start_path(pls, &local_v);
- pls->bytecnt += fprintf( pls->OutFile, "Move %d %d\n", xa[0], ya[0] );
- local_v.x1st = xa[0]; local_v.y1st = ya[0];
- /* }*/
- for (i = 1; i < npts; i++) { /* Add new point to path */
- pls->bytecnt += fprintf( pls->OutFile, "Line %d %d\n", xa[i], ya[i] );
- local_v.xlast = xa[i]; local_v.ylast = ya[i] ;
- if ((local_v.x1st != local_v.xlast) || (local_v.y1st != local_v.ylast)) {
- local_v.path_is_valid = TRUE;
- }
- }
- arcmkdrawf_end_path(pls, &local_v);
- dev->xold = xa[ npts - 1 ];
- dev->yold = ya[ npts - 1 ];
- }
-
- /*----------------------------------------------------------------------*\
- * plD_eop_arcmkdrawf()
- *
- * End of page.
- \*----------------------------------------------------------------------*/
-
- void
- plD_eop_arcmkdrawf(PLStream *pls)
- {
- #ifdef __riscos
- char *sys_string;
- #endif
- if (local_v.path_is_open != FALSE) {
- arcmkdrawf_end_path(pls, &local_v);
- }
- fclose(pls->OutFile);
- #ifdef __riscos
- sys_string=malloc(sizeof(pls->FileName)+15);
- if (sys_string == NULL) {
- plwarn("malloc failed - cannot change filetype to TXT");
- }
- else {
- strcpy(sys_string, "settype ");
- strcat(sys_string, pls->FileName);
- strcat(sys_string, " FFF");
- /* printf("system string is %s", sys_string);*/
- system(sys_string);
- free(sys_string);
- }
- #endif
- }
-
- /*----------------------------------------------------------------------*\
- * plD_bop_arcmkdrawf()
- *
- * Set up for the next page.
- * Advance to next family file if necessary (file output).
- \*----------------------------------------------------------------------*/
-
- void
- plD_bop_arcmkdrawf(PLStream *pls)
- {
- PLDev *dev = (PLDev *) pls->dev;
-
- dev->xold = UNDEFINED;
- dev->yold = UNDEFINED;
-
- if (!pls->termin){
- plGetFam(pls);
- }
- pls->famadv = 1; /*advance to next member*/
- pls->page++;
- fputs( "#Created by plplot driver\n", pls->OutFile );
- fputs( "Options {\n", pls->OutFile );
- fputs( " PaperSize 4 # A4\n", pls->OutFile );
- fputs( " Limits {\n", pls->OutFile );
- fputs( " Landscape\n", pls->OutFile );
- fputs( " }\n", pls->OutFile );
- fputs( "}\n", pls->OutFile );
- fputs( "Path {\n", pls->OutFile );
- fputs( "FillColour r0g0b0\n", pls->OutFile );
- fputs( "OutlineColour r0g0b0\n", pls->OutFile );
- fputs( "Width 0\n", pls->OutFile );
- fputs( "Move 0 594\n", pls->OutFile );
- fputs( "Line 840 594\n", pls->OutFile );
- fputs( "Line 840 0\n", pls->OutFile );
- fputs( "Line 0 0\n", pls->OutFile );
- fputs( "Line 0 594\n", pls->OutFile );
- fputs( "Close\n", pls->OutFile );
- fputs( "}\n", pls->OutFile );
- }
-
- /*----------------------------------------------------------------------*\
- * plD_tidy_arcmkdrawf()
- *
- * Close graphics file or otherwise clean up.
- \*----------------------------------------------------------------------*/
-
- void
- plD_tidy_arcmkdrawf(PLStream *pls)
- {
- #ifdef __riscos
- char *sys_string;
- #endif
- if (local_v.path_is_open != FALSE) {
- arcmkdrawf_end_path(pls, &local_v);
- }
- fclose(pls->OutFile);
- #ifdef __riscos
- sys_string=malloc(sizeof(pls->FileName)+15);
- if (sys_string == NULL) {
- plwarn("malloc failed - cannot change filetype to TXT");
- }
- else {
- strcpy(sys_string, "settype ");
- strcat(sys_string, pls->FileName);
- strcat(sys_string, " FFF");
- system(sys_string);
- free(sys_string);
- }
- #endif
-
- }
-
- /*----------------------------------------------------------------------*\
- * plD_state_arcmkdrawf()
- *
- * Handle change in PLStream state (color, pen width, fill attribute, etc).
- \*----------------------------------------------------------------------*/
-
- void
- plD_state_arcmkdrawf(PLStream *pls, PLINT op)
- {
- switch (op) {
-
- case PLSTATE_WIDTH:
- local_v.width_has_changed = TRUE;
- break;
-
- case PLSTATE_COLOR0:
- local_v.color_0_has_changed = TRUE;
- break;
-
- case PLSTATE_COLOR1:
- local_v.color_1_has_changed = TRUE;
- break;
-
- case PLSTATE_FILL:
- fputs( "#PLSTATE_FILL - ignored\n", pls->OutFile );
- break;
-
- default:
- fprintf( pls->OutFile, "#PLSTATE_DEFAULT - code = %d ignored\n", op );
- break;
- }
- }
-
- /*----------------------------------------------------------------------*\
- * plD_esc_arcmkdrawf()
- *
- * Escape function.
- \*----------------------------------------------------------------------*/
-
- void
- plD_esc_arcmkdrawf(PLStream *pls, PLINT op, void *ptr)
- {
- switch (op) {
-
- case PLESC_FILL:
- local_v.fill_req = TRUE;
- local_v.fill_color = pls->curcolor;
- plD_polyline_arcmkdrawf(pls, pls->dev_x, pls->dev_y, pls->dev_npts);
- break;
-
- default:
- fprintf( pls->OutFile, "#PLESC_DEFAULT - code = %d ignored\n", op );
- break;
- }
-
- }
-
- /*----------------------------------------------------------------------*\
- * arcmkdrawf_start_path()
- *
- * start a new path function.
- \*----------------------------------------------------------------------*/
-
- static void
- arcmkdrawf_start_path(PLStream *pls, struct lvs *l_v)
- {
- l_v->path_is_open = TRUE;
- l_v->path_is_valid = FALSE;
- fputs( "Path {\n", pls->OutFile );
- if ( pls->width == 0 ) {/*i.e. not initialised*/
- fputs( "Width 0.5\n", pls->OutFile );
- } else {
- fprintf( pls->OutFile, "Width %d\n", pls->width);
- }
- fprintf( pls->OutFile, "OutlineColour r%dg%db%d\n", pls->curcolor.r, pls->curcolor.g, pls->curcolor.b);
- if (l_v->fill_req == TRUE) {
- l_v->fill_req = FALSE;
- l_v->must_close = TRUE;
- }
- l_v->color_0_has_changed = FALSE;
- l_v->color_1_has_changed = FALSE;
-
- }
-
- /*----------------------------------------------------------------------*\
- * arcmkdrawf_start_path()
- *
- * start a new path function.
- \*----------------------------------------------------------------------*/
-
- static void
- arcmkdrawf_end_path(PLStream *pls, struct lvs *l_v)
- {
- /* this should patch rogue draw paths */
- if (l_v->path_is_valid == FALSE) {
- fputs( "OutlineColour Transparent\nWidth 0\n", pls->OutFile );
- fprintf( pls->OutFile, "Move %d %d\n", l_v->xlast+1, l_v->ylast+1);
- }
- if (l_v->must_close == TRUE) {
- fprintf( pls->OutFile, "FillColour r%dg%db%d\n", l_v->fill_color.r, l_v->fill_color.g, l_v->fill_color.b);
- fputs( "close\n", pls->OutFile );
- l_v->must_close = FALSE;
- }
- fputs( "}\n", pls->OutFile );
- l_v->path_is_open = FALSE;
- }
-
-
- /*----------------------------------------------------------------------*\
- * arcmkdrawf_change_colour0()
- *
- * change colour0 function.
- \*----------------------------------------------------------------------*/
-
- static void
- arcmkdrawf_change_colour0(PLStream *pls, struct lvs *l_v)
- {
- fprintf( pls->OutFile, "OutlineColour r%dg%db%d\n", pls->curcolor.r, pls->curcolor.g, pls->curcolor.b);
- l_v->color_0_has_changed = FALSE;
-
- }
-
- /*----------------------------------------------------------------------*\
- * arcmkdrawf_change_colour1()
- *
- * change colour1 function.
- \*----------------------------------------------------------------------*/
-
- static void
- arcmkdrawf_change_colour1(PLStream *pls, struct lvs *l_v)
- {
- fprintf( pls->OutFile, "OutlineColour r%dg%db%d\n", pls->curcolor.r, pls->curcolor.g, pls->curcolor.b);
- l_v->color_1_has_changed = FALSE;
-
- }
-
- /*----------------------------------------------------------------------*\
- * arcmkdrawf_change_width()
- *
- * change colour1 function.
- \*----------------------------------------------------------------------*/
-
- static void
- arcmkdrawf_change_width(PLStream *pls, struct lvs *l_v)
- {
- l_v->width_has_changed = FALSE;
- fprintf( pls->OutFile, "Width %d\n", pls->width);
- }
-
-
- #else
- int
- pldummy_arcmkdrawf(void)
- {
- return 0;
- }
-
- #endif /* PLD_arcmkdrawf */
-
-